package LeetCode.month02.day33;

public class No3195 {
    public static void main(String[] args) {
        System.out.println(minimumArea(new int[][]{{0,0,0},{0,0,0}}));
    }
    public static int minimumArea(int[][] grid) {
        int left = Integer.MAX_VALUE;
        int top = Integer.MAX_VALUE;
        int right = Integer.MIN_VALUE;
        int bottom = Integer.MIN_VALUE;
        for (int i = 0; i < grid.length; i++) {
            for (int j = 0; j < grid[0].length; j++) {
                if(grid[i][j]==1){
                    left = Math.min(j,left);
                    right = Math.max(right,j);
                    top = Math.min(i,top);
                    bottom = Math.max(bottom,i);
                }
            }
        }
        if(left==Integer.MAX_VALUE) return 0;
        return (right-left+1)*(bottom-top+1);
    }
}
